﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
//
using DbFrame.Class;
using Microsoft.Extensions.Logging;

namespace HzyAdmin
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            ConfigModel.SqlServer = Configuration.GetSection("ConnectionStrings:SqlServer").Value;
            //自定义 视图 
            services.Configure<Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions>(item =>
            {
                item.AreaViewLocationFormats.Clear();
                //item.AreaViewLocationFormats.Add("/Categories/{2}/Views/{1}/{0}.cshtml");
                //item.AreaViewLocationFormats.Add("/Categories/{2}/Views/Shared/{0}.cshtml");
                item.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
                item.AreaViewLocationFormats.Add("/Views/{1}/{0}.cshtml");

                item.AreaViewLocationFormats.Add("/Areas/{2}/Views/{1}/{0}.cshtml");
                item.AreaViewLocationFormats.Add("/Areas/{2}/Views/Shared/{0}.cshtml");

                item.AreaViewLocationFormats.Add("/Areas/{2}/Views/Sys/{1}/{0}.cshtml");//系统管理
                item.AreaViewLocationFormats.Add("/Areas/{2}/Views/Base/{1}/{0}.cshtml");//基础信息管理
                item.AreaViewLocationFormats.Add("/Areas/{2}/Views/Operate/{1}/{0}.cshtml");//运营管理
                item.AreaViewLocationFormats.Add("/Areas/{2}/Views/Statistics/{1}/{0}.cshtml");//统计管理
                item.AreaViewLocationFormats.Add("/Areas/{2}/Views/Operate/{1}/{0}.cshtml");//基础信息管理

                //"~/Areas/{2}/Views/{1}/{0}.cshtml",
                //"~/Areas/{2}/Views/Shared/{0}.cshtml",
                //"~/Areas/{2}/Views/Sys/{1}/{0}.cshtml",//系统管理
                //"~/Areas/{2}/Views/Base/{1}/{0}.cshtml",//系统管理
                //"~/Areas/{2}/Views/Operate/{1}/{0}.cshtml",//运营管理
                //"~/Areas/{2}/Views/Statistics/{1}/{0}.cshtml",//统计管理
                //"~/Areas/{2}/Views/WX/{1}/{0}.cshtml",//统计管理
            });

            services.AddMvc(item =>
            {
                item.Filters.Add<Aop.AopExceptionFilter>();
                item.Filters.Add<Aop.AopActionFiter>();
            });
            //services.AddMvcCore(item =>
            //{

            //});
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                //routes.MapRoute(
                //    name: "/",
                //    template: "{area:exists}/{controller=Index}/{action=Index}/{id?}"
                //    );

                routes.MapRoute(
                    name: "area",
                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
                    );

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}"
                    );

            });
        }




    }
}
